package com.ecommerce.dal.common;

import java.util.Date;
import java.util.List;

import com.ecommerce.dal.entity.Item;
import com.ecommerce.dal.entity.ItemHistory;
import com.ecommerce.dal.service.impl.ItemManagementService;
import com.ecommerce.dal.service.impl.ItemManagerService;

public class TestItemManagement {

	public TestItemManagement(ItemManagementService itemManagementService,
			ItemManagerService itemManagerService) {
		/**
		 * Don't forget to set fetching strategy in ItemHistory entity to EAGER
		 * fetching for Item , in order for this test class to work
		 */

		Item item = itemManagerService.retrieveItem(1L);
		ItemHistory itemHistory = new ItemHistory();

		itemHistory.setItem(item);
		itemHistory.setItemIncludeDate(new Date());
		itemHistory.setItemTotalPrice(item.getTotalItemPrice());

		/** Inserting new history for selected Item */
		itemManagementService.saveItemHistory(itemHistory);

		/** retrieving Item History */
		List<ItemHistory> itemHistory2 = itemManagementService
				.retrieveItemHistory(item.getItemId());
		for (ItemHistory itemHistoryX : itemHistory2) {
			System.out.println("Item Id: " + itemHistoryX.getItem().getItemId()
					+ " , Item Include Date : "
					+ itemHistoryX.getItemIncludeDate() + " , Item Name: "
					+ itemHistoryX.getItem().getItemName());
		}

	}

}
